using System.IO;
using UnityEngine;

public class ScreenshotHelper
{
    public static void Capture()
    {
        string filepath = GetSaveScreenshotFilePath();
        ScreenCapture.CaptureScreenshot(filepath, 0);  
        GameDebug.Log($"截屏完成：{filepath}");
    }
    private static string screenshot_file =>
        Application.dataPath.Substring(0, Application.dataPath.Length - "Assets".Length) + "Screenshots/screenshot";

    static string GetSaveScreenshotFilePath()
    {
        var dir = Path.GetDirectoryName(screenshot_file);
        if (!Directory.Exists(dir))
        {
            Directory.CreateDirectory(dir);
        }

        int id = 1;
        string curFilePath = screenshot_file + $"_{id}.png";
        while (File.Exists(curFilePath))
        {
            id++;
            curFilePath = screenshot_file + $"_{id}.png";
        }

        return curFilePath;
    }
    
}
